package com.lz.springboot.mongo;  
  
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;

import com.lz.springboot.mongo.common.MongoConstants;  
  
@Configuration
@ConfigurationProperties(prefix = "spring.data.mongo.second")  
public class SecondMongoConfig extends  AbstractMongoConfig{       
	
    @Override 
    public @Bean(name = MongoConstants.SECOND_MONGO_TEMPLATE) MongoTemplate getMongoTemplate() throws Exception {          
        MongoDbFactory factory = mongoDbFactory();  
        MongoMappingContext mongoMappingContext = new MongoMappingContext();  
        MappingMongoConverter converter = new MappingMongoConverter(new DefaultDbRefResolver(factory), mongoMappingContext); 
        //去除save的时候，自动加入的字段"_class"
        converter.setTypeMapper(new DefaultMongoTypeMapper(null));  
        return new MongoTemplate(factory, converter);     
    }  
}